package cn.donting.jme.expansion.builder.light;

import cn.donting.jme.expansion.attribute.Attribute;
import cn.donting.jme.expansion.attribute.lmpl.FloatAttribute;
import cn.donting.jme.expansion.attribute.lmpl.Vector3fAttribute;
import cn.donting.jme.ioc.Bean;
import com.formdev.flatlaf.extras.FlatSVGIcon;
import com.jme3.light.PointLight;

import javax.swing.*;
import java.util.List;

@Bean
public class PointLightAttributeBuilder extends LightAttributeBuilder<PointLight> {
    @Override
    public boolean isHandle(Object o) {
        return o instanceof PointLight;
    }

    @Override
    public PointLight newInstance() {
        PointLight pointLight = new PointLight();
        pointLight.setName("点光源");
        return pointLight;
    }

    @Override
    public Icon getIcon(int size) {
        return new FlatSVGIcon("icon/pointLight.svg",size,size);
    }
    @Override
    public Icon getActiveIcon(int size) {
        return new FlatSVGIcon("icon/pointLight-active.svg",size,size);
    }
    @Override
    public String getName() {
        return "点光源";
    }

    @Override
    public void attribute(List<Attribute> attributes, PointLight pointLight) {
        super.attribute(attributes,pointLight);
        Vector3fAttribute position = new Vector3fAttribute("位置");
        position.setValue(pointLight.getPosition());
        position.setValueChangeListener(true, newValue -> {
            pointLight.setPosition(newValue);
        });
        attributes.add(position);
        FloatAttribute radius = new FloatAttribute("半径");
        radius.setValue(pointLight.getRadius());
        radius.setValueChangeListener(true, newValue -> {
            pointLight.setRadius(newValue);
        });
        attributes.add(radius);
    }
}
